home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Form1
- BackColor = &H00C0C0C0&
- Caption = "Bitmap Tiling Example"
- ClientHeight = 4575
- ClientLeft = 2580
- ClientTop = 2625
- ClientWidth = 5745
- Height = 4980
- Left = 2520
- LinkTopic = "Form1"
- ScaleHeight = 4575
- ScaleWidth = 5745
- Top = 2280
- Width = 5865
- Begin Label Label1
- Alignment = 2 'Center
- BackColor = &H00FFFFFF&
- BackStyle = 0 'Transparent
- Caption = "Drag the tiles above onto the background to form connecting tunnels. To remove a tile, double-click over it."
- ForeColor = &H00000000&
- Height = 495
- Left = 240
- TabIndex = 0
- Top = 4020
- Width = 5295
- End
- Begin Image imgTileA
- Height = 675
- Index = 5
- Left = 4800
- Picture = TILES.FRX:0000
- Top = 3180
- Width = 675
- End
- Begin Image imgTileA
- Height = 675
- Index = 4
- Left = 3900
- Picture = TILES.FRX:04B2
- Top = 3180
- Width = 675
- End
- Begin Shape shpHolder
- BackColor = &H0080FF80&
- BackStyle = 1 'Opaque
- Height = 795
- Index = 5
- Left = 4740
- Top = 3120
- Width = 795
- End
- Begin Shape shpHolder
- BackColor = &H0080FF80&
- BackStyle = 1 'Opaque
- Height = 795
- Index = 4
- Left = 3840
- Top = 3120
- Width = 795
- End
- Begin Image imgTileA
- Height = 675
- Index = 3
- Left = 3000
- Picture = TILES.FRX:0964
- Top = 3180
- Width = 675
- End
- Begin Image imgTileA
- Height = 675
- Index = 2
- Left = 2100
- Picture = TILES.FRX:0E16
- Top = 3180
- Width = 675
- End
- Begin Image imgTileA
- Height = 675
- Index = 1
- Left = 1200
- Picture = TILES.FRX:12C8
- Top = 3180
- Width = 675
- End
- Begin Shape shpHolder
- BackColor = &H0080FF80&
- BackStyle = 1 'Opaque
- Height = 795
- Index = 3
- Left = 2940
- Top = 3120
- Width = 795
- End
- Begin Shape shpHolder
- BackColor = &H0080FF80&
- BackStyle = 1 'Opaque
- Height = 795
- Index = 2
- Left = 2040
- Top = 3120
- Width = 795
- End
- Begin Shape shpHolder
- BackColor = &H0080FF80&
- BackStyle = 1 'Opaque
- Height = 795
- Index = 1
- Left = 1140
- Top = 3120
- Width = 795
- End
- Begin Image imgTileA
- Height = 675
- Index = 0
- Left = 300
- Picture = TILES.FRX:177A
- Top = 3180
- Width = 675
- End
- Begin Shape shpHolder
- BackColor = &H0080FF80&
- BackStyle = 1 'Opaque
- Height = 795
- Index = 0
- Left = 240
- Top = 3120
- Width = 795
- End
- Begin Shape shpBox
- BackColor = &H0080FF80&
- BackStyle = 1 'Opaque
- Height = 2700
- Left = 180
- Top = 180
- Width = 5400
- End
- Option Explicit
- '--------------------------------------------------
- ' TILES.FRM
- '--------------------------------------------------
- ' There's one base tile for each tile picture.
- Const LAST_BASE_TILE = 5
- ' Boolean indicating if we're currently dragging
- ' an object.
- Dim Dragging As Integer
- ' Used while dragging an object.
- Dim Ofs As tPoint
- ' The index of the next image to be created in
- ' the imgTile control array.
- Dim NextImage As Integer
- Sub CenterXY (Ctrl As Control, APoint As tPoint)
- '--------------------------------------------------
- ' Find the center coordinates for this control.
- '--------------------------------------------------
- APoint.X = (Ctrl.Width / 2) + Ctrl.Left
- APoint.Y = (Ctrl.Height / 2) + Ctrl.Top
- End Sub
- Sub Form_Load ()
- '--------------------------------------------------
- ' Initialize the next image counter, used to
- ' load tile controls on the fly.
- '--------------------------------------------------
- NextImage = LAST_BASE_TILE + 1
- End Sub
- Sub imgTileA_DblClick (Index As Integer)
- '--------------------------------------------------
- ' Double-clicking on a placed tile makes it
- ' disappear. We do this by simply unloading
- ' the control.
- '--------------------------------------------------
- ' Don't unload a base tile!
- If Index > LAST_BASE_TILE Then
- Unload imgTileA(Index)
- End If
- End Sub
- Sub imgTileA_MouseDown (Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
- '--------------------------------------------------
- ' If the mouse is held down over an object, prepare
- ' to drag that object.
- '--------------------------------------------------
- If Index > LAST_BASE_TILE Then Exit Sub
- Dragging = True
- Ofs.X = X
- Ofs.Y = Y
- End Sub
- Sub imgTileA_MouseMove (Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
- '--------------------------------------------------
- ' Drag an object if the mouse is clicked and
- ' dragged over it.
- '--------------------------------------------------
- If Index > LAST_BASE_TILE Then Exit Sub
- If Dragging Then
- imgTileA(Index).Move imgTileA(Index).Left + (X - Ofs.X), imgTileA(Index).Top + (Y - Ofs.Y)
- End If
- End Sub
- Sub imgTileA_MouseUp (Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
- '--------------------------------------------------
- ' End the drag process and create and position
- ' the new tile.
- '--------------------------------------------------
- Dim Center As tPoint
- If Index > LAST_BASE_TILE Then Exit Sub
- Dragging = False
- ' Calculate the center coordinates for the tile.
- CenterXY imgTileA(Index), Center
- ' If the user has placed the tile inside the background,
- ' then create a new tile control and place it on the
- ' background.
- If InsideControl(shpBox, Center) Then
- ' Create a new image control to drop at this location
- Load imgTileA(NextImage)
- imgTileA(NextImage).Picture = imgTileA(Index).Picture
-
- ' Adjust the control's position so that it "jumps"
- ' to the nearest tile boundary.
- imgTileA(NextImage).Left = shpBox.Left + (imgTileA(Index).Width * (Center.X \ imgTileA(Index).Width))
- imgTileA(NextImage).Top = shpBox.Top + (imgTileA(Index).Height * (Center.Y \ imgTileA(Index).Height))
- imgTileA(NextImage).Visible = True
- ' Make sure the tile is on top of the background,
- ' not hiding underneath it!
- imgTileA(NextImage).ZOrder 0
- NextImage = NextImage + 1
- End If
- ' Move the base tile back to its holding position.
- imgTileA(Index).Left = shpHolder(Index).Left + 60
- imgTileA(Index).Top = shpHolder(Index).Top + 60
- End Sub
- Function InsideControl (Ctrl As Control, APoint As tPoint)
- '--------------------------------------------------
- ' Is the point Apoint inside Control Ctrl?
- '--------------------------------------------------
- InsideControl = False
- If (APoint.X >= Ctrl.Left) And (APoint.X <= (Ctrl.Left + Ctrl.Width)) Then
- If (APoint.Y >= Ctrl.Top) And (APoint.Y <= (Ctrl.Top + Ctrl.Height)) Then
- InsideControl = True
- End If
- End If
- End Function
-